-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
node: improve nextTick performance #1571
Conversation
d09cb2f
to
1802b8d
Compare
callback(); | ||
threw = false; | ||
} finally {} | ||
return threw; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the point of a try { ... } finally {}
with an empty finalizer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just copied from the original function (_tickCallback
/_tickDomainCallback
). I can safely delete it I guess? Unless it was originally supposed to catch exceptions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in _tickCallback
there's code in the finalizer – if control passes to the finalizer, tickDone
is called before the exception propagates as usual. It should be replicable by moving the try {} finally { if (threw) tickDone() }
back up into _tickCallback
, wrapping these lines in the TryClause.
@chrisdickinson I've adjusted the benchmarks, is that what you had in mind? |
else if (i % 2 === 0) | ||
process.nextTick(cb2, false, 5.1); | ||
else | ||
process.nextTick(cb1, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might add a case for process.nextTick(cb)
by itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I should merge the pre-existing non-args benchmark with this one?
@mscdex re: benchmarks, yep! I had one other pony request relating to them (related to including |
@@ -0,0 +1,36 @@ | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'use strict'
?
A bit verbose, but if it offers the performance improvements you said then I'm okay with the change. |
} finally { | ||
if (threw) | ||
tickDone(); | ||
args = tock.args; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a nit: would you mind adding a comment briefly explaining why this call is separated into a switch statement, for future readers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
This commit uses separate functions to isolate deopts caused by try-catches and avoids fn.apply() for callbacks with small numbers of arguments. These changes improve performance by ~1-40% in the various nextTick benchmarks.
Cool – after the changes, are the numbers still ~2-42% better than the previous implementation? If so, LGTM! |
@chrisdickinson Yep, performance is still in the same range. |
This commit uses separate functions to isolate deopts caused by try-catches and avoids fn.apply() for callbacks with small numbers of arguments. These changes improve performance by ~1-40% in the various nextTick benchmarks. PR-URL: #1571 Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
Landed in c7782c0. |
This commit uses separate functions to isolate deopts caused by try-catches and avoids fn.apply() for callbacks with small numbers of arguments. These changes improve performance by ~1-40% in the various nextTick benchmarks. PR-URL: nodejs#1571 Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
This commit uses separate functions to isolate deopts caused by
try-finallys and avoids
fn.apply()
for callbacks with small numbersof arguments.
These changes improve performance by ~2-42% in the various
nextTick benchmarks.